import {
  createRouter,
  createWebHashHistory,
  RouteRecordRaw,
  RouterOptions,
} from "vue-router";
import Home from "../views/home/index.vue";
import Car from "../views/car/index.vue";
import Me from "../views/me/index.vue";
import Mall from "../views/mall/index.vue"
import Map from "../views/map/index.vue"
import Menu from "../views/menu/index.vue";
import Top from "../components/top.vue";
import { Search } from "vant";



const routes: RouteRecordRaw[] = [
  {
    path: "/",
    components: {
      default: Home,
      menu: Menu,
      top: Top,
    },
    meta: {
      hidden: false, //
      title: "首页",
      icon: "home-o",
    },
    name: "home",
  },
  {
    path: "/mall",
    components: {
      default: Mall,
      menu: Menu,
      top: Top,
    },
    meta: {
      hidden: false, //
      title: "商城",
      icon: "bag-o",
    },
    name: "mall",
  },
  {
    path: "/map",
    components: {
      default: Map,
      menu: Menu,
      top: Top,
    },
    meta: {
      hidden: false, //
      title: "地图",
      icon: "map-marked",
    },
    name: "map",
  },
  {
    path: "/car",
    components: {
      default: Car,
      menu: Menu,
      top: Top,
    },
    meta: {
      hidden: false, //
      title: "购物车",
      icon: "cart-o",
    },
    name: "car",
  },
  
  {
    path: "/me",
    components: {
      // 命名视图
      default: Me,
      menu: Menu,
      top: Top,
    },
    meta: {
      hidden: false, //
      title: "我的",
      icon: "contact",
    },
    name: "me",
  },
  
  {
    path: "/goods",
    components: {
      default: () => import("../views/goods/index.vue"),
      top: Top,
    },
    meta: {
      hidden: true, //
      title: "商品详情",
      icon: "like-o",
    },
    name: "goods",
  },
  {
    path: "/login",

    component: () => import("../views/login/index.vue"),
    meta: {
      hidden: true, //
      title: "登录",
      icon: "like-o",
    },
    name: "login",
  },
  {
    path: "/register",
    component: () => import("../views/register/index.vue"),
    meta: {
      hidden: true, //
      title: "注册",
      icon: "like-o",
    },
    name: "register",
  },
];

const router = createRouter({
  routes,
  history: createWebHashHistory(),
});

router.beforeEach((to, from, next) => {
  //
  document.title = to.meta.title as string;
  next();
});

export default router;
